<template>
	<view class="exam-container">
		<u-sticky bgColor="#FFFFFF">
			<view class="exam-tabs">
				<u-tabs :list="examType" @click="changeType" />
			</view>
		</u-sticky>
		<view class="exam-content">
			<u-cell-group>
				<u-cell isLink v-for="item in exam" :key="item.id" :title="item.name" :value="item.subjectName" />
			</u-cell-group>
			<u-divider text="暂无数据"></u-divider>
		</view>
	</view>
</template>

<script>
	import http from '../../http.js'
	export default {
		data() {
			return {
				examType: [{
					id: 1,
					name: '固定试卷',
				}, {
					id: 4,
					name: '时段试卷',
				}],
				exam: []
			}
		},
		methods: {
			changeType(index) {
				this.getPageList(this.examType[index.index].id)
			},
			async getPageList(type) {
				let ret = await http({
					url: '/api/student/exam/paper/pageList',
					method: 'POST',
					data: {
						paperType: type,
						subjectId: '',
						pageIndex: 1,
						pageSize: 30
					}
				})
				// console.log(ret);
				this.exam = ret.response.list
				this.getSubjectList()
			},
			getSubjectList() {
				http({
					url: '/api/student/education/subject/list',
					method: 'POST'
				}).then(res => {
					// console.log(res);
					const subject = res.response
					this.exam = this.exam.filter(item => {
						return subject.find(it => {
							return it.id == item.subjectId
						})
					})
					this.exam.forEach(item => {
						subject.forEach(it => {
							it.id == item.subjectId ? item.subjectName = it.name : item.subjectName
						})
					})
					// console.log(this.exam);
				})
			}
		},
		onLoad() {
			this.getPageList(1)
		},
		onShow() {
			this.getPageList(1)
		}
	}
</script>

<style lang="scss">
	.exam-container {
		height: calc(100% - 50px);

		.exam-tabs {
			display: flex;
			justify-content: center;
		}

		.exam-content {
			margin-bottom: 50rpx;
		}
	}
</style>